﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.DataVisualization.Charting;

using MusicStore.Domain.POCO;
using MusicStore.Domain.Concrete;
using System.IO;
using System.Reflection;
namespace MusicStore.WebUI.Controllers
{
  public class StoreController : Controller
  {
    EFDbContext storeDB = new EFDbContext();
    //
    /* GET: /Store/

    public String Index()
    {
        return "Hello from Store.Index";
    }
    */
    // GET: /Store/

    public ActionResult Index()
    {
      var genres = storeDB.Genres.ToList<Genre>();
      var albums = storeDB.Albums.ToList<Album>();
        
      MyChart test = new MyChart();
      String startupPath = Assembly.GetAssembly(typeof(MyChart)).Location;
      test.Series.Add(test.addDataSerie(genres, albums));
      test.SaveImage(startupPath+"output.png", ChartImageFormat.Png);
      test.addDataSerieArray(genres, albums);
      ViewBag.ListGenre = test.albumsPerGenre;
      ViewBag.ListAlbums = albums;
      ViewBag.ListGenres = genres;
      return View();
    }
    
    //
    //
    /* GET: /Store/Browse
    public String Browse() 
    {
      return "Hello from Store.Browse";
    }
    */
    //
    /* GET: /Store/Browse?genre=Disco
    public String Browse(string genre)
    {
      string message = HttpUtility.HtmlEncode("Store.Browse, Genre = " + genre);
      return message;
    }
    */
    // GET: /Store/Browse?genre=Disco
    public ActionResult Browse(string genre)
    {
      var genreModel = storeDB.Genres.Include("Albums").Single(g => g.Name == genre);
      return View(genreModel);
    }
    //
    /* GET: /Store/Details
    public String Details()
    {
      return "Hello from Store.Details";
    }
     */
    //
    /*GET: /Store/Details/5
    public String Details(int id)
    {
      string message = HttpUtility.HtmlEncode("Store.Details, ID = " + id);
      return message;
    }
    */
    //
    public ActionResult Details(int id)
        {
          var album = storeDB.Albums.Find(id);
          return View(album);
        }
  }
}
